package com.scy.java.object.StringDemo;

import java.util.Arrays;

public class Demo {
    public static void main(String[] args) {
//        int[] arr = {12,23,21,3124,12,4};
//        printArr(arr);
        //动态创建数组，并给数组添加随机数
        int[] array = new int[5];
        for (int i = 0; i <array.length ; i++) {
            //添加1-100的随机数
            array[i] = (int)(Math.random()*100+1);
        }
        System.out.println(Arrays.toString(array));
        printArr(array);
    }
    public static void printArr(int[] arr){

        System.out.print("[");
        for (int i = 0; i < arr.length; i++) {
            if (i==arr.length-1){//表示数组最后一个元素
                System.out.print(arr[i]);
                break;
            }else {
                System.out.print(arr[i]+",");
            }
        }
        System.out.print("]");
    }
}
